package cn.broadmax.boot.modules.jzm.controller;


import cn.broadmax.boot.base.SuperController;
import cn.broadmax.boot.base.message.SResult;
import cn.broadmax.boot.modules.jzm.entity.JzStore;
import cn.broadmax.boot.modules.jzm.mapper.JzStoreMapper;
import cn.broadmax.boot.modules.jzm.service.IJzStoreService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 案管柜 前端控制器
 * </p>
 *
 * @author jexx
 * @since 2021-05-24
 */
@Api(tags = "案管柜配置")
@RestController
@RequestMapping("/jzm/jzStore")
@RequiredArgsConstructor
public class JzStoreController extends SuperController {

    @Autowired
    private final IJzStoreService iJzStoreService;

    @Autowired
    private JzStoreMapper jzStoreMapper;


    @ApiOperation("分页查询案管柜配置")
    @GetMapping(value = "")
    public SResult<IPage<JzStore>> pageTypes(){
        List<JzStore> list = jzStoreMapper.selectList(null);
        QueryWrapper<JzStore> wrapper = new QueryWrapper<>();
        IPage<JzStore> page = iJzStoreService.page(getPage(), wrapper);
        return SResult.ok("", page);
    }

    @ApiOperation("案管柜配置修改")
    @PutMapping(value = "/update/{id}")
    public SResult<Boolean> updatePage(@PathVariable Integer id, @RequestBody JzStore jzStore){
        jzStore.setId(id);
        iJzStoreService.updateById(jzStore);
        return SResult.ok("", Boolean.TRUE);
    }

    @ApiOperation("案管柜配置添加")
    @PutMapping(value = "/insert")
    public SResult<Boolean> InsertPage(@RequestBody JzStore jzStore){
        jzStoreMapper.insert(jzStore);
        return SResult.ok("", Boolean.TRUE);
    }

    @ApiOperation("案管柜配置删除")
    @DeleteMapping(value = "/delete/{id}")
    public SResult<Boolean> DeletePage(@PathVariable String id){
        iJzStoreService.removeById(id);
        return SResult.ok("", Boolean.TRUE);
    }

}
